﻿using Framework.Core.Recorder;
using Rhino.Mocks;
using Xunit;

namespace Framework.Tests.Core.Recorder
{
    public class StateFullCallKeyBuilderTest
    {
        private readonly StateFullCallKeyBuilder target;
        private readonly MockRepository mockRepository = new MockRepository();
        private readonly ICallKeyBuilder callKeyBuilderMock;

        public StateFullCallKeyBuilderTest()
        {
            callKeyBuilderMock = mockRepository.StrictMock<ICallKeyBuilder>();
            target = new StateFullCallKeyBuilder(callKeyBuilderMock);
        }

        [Fact]
        public void Should_remember_order_call_in_order_to_be_state_full()
        {
            for (var i = 1; i < 10; i++)
            {
                BuildTime(i);
            }
        }

        private void BuildTime(int counter)
        {
            callKeyBuilderMock.Expect(x => x.Build(null)).Return("toto");
            mockRepository.ReplayAll();
            var actual = target.Build(null);
            mockRepository.VerifyAll();

            Assert.Equal(string.Format("{0}_toto", counter), actual);
        }

        [Fact]
        public void Should_reset_counter_every_construction()
        {
            var target2 = new StateFullCallKeyBuilder(callKeyBuilderMock);

            callKeyBuilderMock.Expect(x => x.Build(null)).Return("toto").Repeat.Twice();

            mockRepository.ReplayAll();
            var actual = target2.Build(null);
            var expected = target.Build(null);
            mockRepository.VerifyAll();

            Assert.Equal(expected, actual);
        }
    }
}